'''
Date: 2022-03-10 16:22:16
Author: chenbin
LastEditors: chenbin
LastEditTime: 2022-03-10 16:50:13
FilePath: slcan_test.py
Description: 
'''
import can
import threading
import time
import random

def print_message(msg):
    print(msg)

if __name__ == "__main__":
    # RX part
    #bus_rx = can.interface.Bus('virtual_ch', bustype='virtual')
    canbus = can.interface.Bus('COM32', bustype='slcan')
    
    logger = can.Logger("logfile.asc")  # save log to asc file
    listeners = [
        print_message,  # Callback function, print the received messages
        logger,  # save received messages to asc file
    ]
    notifier = can.Notifier(canbus, listeners)

    running = True
    while running:
        input()
        running = False

    # It's important to stop the notifier in order to finish the writting of asc file
    notifier.stop()
    # stops the bus
    canbus.shutdown()


